package com.loong.prototype;

public class Main {
    public static void main(String[] args) {
        // 创建一个 Attachment 对象
        Attachment attachment = new Attachment();
        attachment.setName("Report.pdf");

        // 创建一个 WeeklyLog 对象并设置 Attachment
        WeeklyLog originalLog = new WeeklyLog();
        originalLog.setName("Weekly Log 1");
        originalLog.setDate("2025-04-01");
        originalLog.setContent("第一周周报");
        originalLog.setAttachment(attachment);

        // 浅克隆
        try {
            WeeklyLog shallowClonedLog = (WeeklyLog) originalLog.clone();

            // 修改浅克隆对象的 Attachment
            shallowClonedLog.getAttachment().setName("Shallow Cloned Report.pdf");

            // 输出结果
            System.out.println("原始附件名称: " + originalLog.getAttachment().getName());
            System.out.println("浅克隆附件名称: " + shallowClonedLog.getAttachment().getName());

            // 比较对象引用
            System.out.println("原始对象和浅克隆对象周报是否相同: " + (originalLog == shallowClonedLog));
            System.out.println("原始和浅克隆附件是否相同: " + (originalLog.getAttachment() == shallowClonedLog.getAttachment()));
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

//        // 深克隆
//        try {
//            WeeklyLog deepClonedLog = (WeeklyLog) originalLog.clone();
//
//            // 修改深克隆对象的 Attachment
//            deepClonedLog.getAttachment().setName("Deep Cloned Report.pdf");
//
//            // 输出结果
//            System.out.println("原始附件名称: " + originalLog.getAttachment().getName());
//            System.out.println("深克隆附件名称: " + deepClonedLog.getAttachment().getName());
//
//            // 比较对象引用
//            System.out.println("原始对象和深克隆对象是否相同: " + (originalLog == deepClonedLog));
//            System.out.println("原始和深克隆附件是否相同: " + (originalLog.getAttachment() == deepClonedLog.getAttachment()));
//        } catch (CloneNotSupportedException e) {
//            e.printStackTrace();
//        }
    }
}
